package com.misty.singleton.client5;


import com.misty.singleton.Person;

// 借助类加载的特性实现单例模式
public class Singleton {

    //防止反射攻击
    private Singleton() {
        if(InnerSingleton.person != null){
            throw new RuntimeException("单例构造器禁止反射调用");
        }
    }

    public static Person instance(){
        return InnerSingleton.person;
    }

    private static class InnerSingleton {
        static Person person = new Person();
    }
}
